/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

package com.facebook.imagepipeline.nativecode;

import ohos.media.image.PixelMap;

/**
 * A fast native rounding filter.
 */
public class NativeRoundingFilter {

    static {
        NativeFiltersLoader.load();
    }

    public static void toCircle(PixelMap bitmap) {
        toCircle(bitmap, false);
    }

    public static void toCircleFast(PixelMap bitmap) {
        toCircleFast(bitmap, false);
    }

    public static void addRoundedCorners(
            PixelMap bitmap,
            int radiusTopLeft,
            int radiusTopRight,
            int radiusBottomRight,
            int radiusBottomLeft) {
        nativeAddRoundedCornersFilter(
                bitmap, radiusTopLeft, radiusTopRight, radiusBottomRight, radiusBottomLeft);
    }

    /**
     * This is a fast, native implementation for rounding a bitmap. It takes the given bitmap and
     * modifies it to be circular.
     *
     * <p>This implementation does not change the underlying bitmap dimensions, it only sets pixels
     * that are outside of the circle to a transparent color.
     *
     * @param bitmap the bitmap to modify
     */
    public static void toCircle(PixelMap bitmap, boolean antiAliased) {
//        Preconditions.checkNotNull(bitmap);
        nativeToCircleFilter(bitmap, antiAliased);
    }

    public static void toCircleFast(PixelMap bitmap, boolean antiAliased) {
//        Preconditions.checkNotNull(bitmap);
        nativeToCircleFastFilter(bitmap, antiAliased);
    }

    public static void toCircleWithBorder(
            PixelMap bitmap, int colorARGB, int borderWidthPx, boolean antiAliased) {
//        Preconditions.checkNotNull(bitmap);
        nativeToCircleWithBorderFilter(bitmap, colorARGB, borderWidthPx, antiAliased);
    }

    private static native void nativeToCircleFilter(PixelMap bitmap, boolean antiAliased);

    private static native void nativeToCircleFastFilter(PixelMap bitmap, boolean antiAliased);

    private static native void nativeToCircleWithBorderFilter(
            PixelMap bitmap, int colorARGB, int borderWidthPx, boolean antiAliased);

    private static native void nativeAddRoundedCornersFilter(
            PixelMap bitmap,
            int radiusTopLeft,
            int radiusTopRight,
            int radiusBottomRight,
            int radiusBottomLeft);
}
